import Taro from "@tarojs/taro";

export function Log(params: {
    eventName: string
}) {
    return Taro.request({
        url: `/api/event/report`,
        method: 'POST',
        data: {
            ...params,
            env: 'test',
            project: '芬必得',
            url: '芬必得小程序',
            sid: Taro.getStorageSync("openId") as string,
            params: {
                eventName: params.eventName
            }
        }
    })
}

export async function GetOpenid() {
    const { code } = await Taro.login();
    if (!code) return;
    const { data } = await Taro.request({
        url: `/api/fbd-music/openid?code=${code}`,
    });
    if (!data)
        return Taro.showToast({ title: "获取openid失败", icon: "error" });

    Taro.setStorageSync("openId", data)
    return Promise.resolve(data)
}